home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Nebula 1
/
Nebula One.iso
/
Financial
/
Amortize1.x
/
Source
/
UnixSource
/
amortize.c
Wrap
C/C++ Source or Header
|
1992-06-13
|
3KB
|
131 lines
/*
*
* loan.c
* amortization program
* purpose: calculates monthly payment, future value
* and creates an amortization schedule
*
* 06/27/84 Bill Gregg, Informatics General Corp.
* 07/12/84 Revision 1
* 07/12/84 Revision 2
* 11/05/85 Jane Medefesser, Implementation NPSN Unix (wilbur)
* compile as follows: 'cc -o <outfile> loan.c -lm'
* 12/05/85 Changes to direct output to a file.
* 03/02/88 Implemented on Eternity 5.3.1
* June 7, 1992 NeXT vanilla c version, Eric Tremblay (NeXTstep version available)
*/
#include <stdio.h>
#include <math.h>
main() /* loan program */
{
/* Declare the variables */
float amt; /* Input for Principal */
float rate; /* Input for Interest Rate */
float mbeg; /* Input for the beginning month */
float ic; /* Interest Payed */
float pmt; /* Payment */
float fv; /* Total Cost */
float term; /* # of months for the term */
float r, temp;
float exp, prin, x, y, yrint = 0;
int mnbr;
int month, i, k, a = 0, yr=1;
char d, filename[9], c;
FILE *fp;
printf("\n *** Amortize ***\n");
printf(" The loan amortization tool.\n");
printf(" NeXT Unix Version 1.0\n\n");
/* Prompt for input from terminal */
printf("Enter principal: ");
scanf("%f", &amt);
printf("Enter term in years: ");
scanf("%f", &term);
printf("Enter interest rate in percent: ");
scanf("%f", &rate);
printf("Enter month payments begin (ex: 8 = August): ");
scanf("%f", &mbeg);
/* compute payment and future value */
r = rate/100.0;
x = 1.0 + r/12.0;
y = term*12.0;
temp = (1.0 / pow(x,y));
pmt = (amt*r/12.0) / (1-temp);
k = term*12;
fv = pmt*k;
ic = fv - amt;
printf("Do you want the report directed to a file or to the screen?");
printf("\n[f = file / s = screen] : ");
d = getchar(); /* This is only here to eat up the '\n' left over
from the last scanf. */
d = getchar();
switch(d) {
case 'f':
d = getchar();
printf("\nEnter a filename: ");
scanf("%s", filename);
while((c = getchar()) != '\n') {
filename[a] = c; a++; }
fp = fopen(filename, "w");
break;
default:
fp = stdout;
break;
}
/* print header */
fprintf(fp,"\n *** Amortize ***\n");
fprintf(fp,"The loan amortization tool.\n\n");
fprintf(fp,"Principal: $%.2f\n", amt);
fprintf(fp,"Interest rate: %3.3f%%\n", rate);
fprintf(fp,"Term of loan in years: %.2f\n", term);
fprintf(fp,"Monthly payment: $%.2f\n", pmt);
fprintf(fp,"Total interest charged: $%.2f\n", ic);
fprintf(fp,"Total cost on loan: $%.2f\n", fv);
fprintf(fp,"\nMonth\tInterest\tPrincipal\tBalance\n");
/* start of loop to print amortization schedule */
mnbr=mbeg;
for (i=1; i<=k; i++) {
month = i;
exp = amt*(r/12.0);
yrint=yrint+exp;
prin = pmt-exp;
amt = amt-prin;
mnbr++;
fprintf(fp,"%d\t %.2f\t\t %.2f\t\t %.2f\n", mnbr-1, exp, prin, amt);
if (mnbr > 12 ) {
fprintf(fp,"\t\tInterest paid for year %d is %.2f\n\n",yr,yrint);
yr++;
yrint=0;
mnbr=1;
}
}
if (mnbr !=1 && mnbr != 13) {
fprintf(fp,"\t\tInterest paid for year %d is %.2f\n\n",yr,yrint);
}
fclose(fp);
}